﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace MiniFox.Data
{
    /// <summary>
    /// 
    /// </summary>
    public interface IDataCommand : IDataCommandAsync
    {
        /// <summary>
        /// 
        /// </summary>
        string Name { get; }
        /// <summary>
        /// sql命令
        /// </summary>
        string CommandText { get; }
        /// <summary>
        /// 命令类型
        /// </summary>
        CommandType CommandType { get; }
        /// <summary>
        /// 
        /// </summary>
        string ProviderName { get; }
        /// <summary>
        /// 
        /// </summary>
        string ConnectionString { get; }
        /// <summary>
        /// 命令参数
        /// </summary>
        ParameterCollection Parameters { get; }
        /// <summary>
        /// 
        /// </summary>
        int TimeOut { get; set; }
        /// <summary>
        /// 
        /// </summary>
        bool Preparable { get; set; }
        /// <summary>
        /// 
        /// </summary>
        event EventHandler<CommandErrorEventArgs> OnError;
        /// <summary>
        /// 
        /// </summary>
        event EventHandler<CommandEventArgs> CommandExecuting;
        /// <summary>
        /// 
        /// </summary>
        event EventHandler<CommandEventArgs> CommandExecuted;
        /// <summary>
        /// 
        /// </summary>
        event EventHandler<CommandEventArgs> CommandCreated;
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        int ExecuteOperation();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        int ExecuteOperation(IEnumerable entities);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        int ExecuteOperation(params object[] entities);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dataTable"></param>
        /// <returns></returns>
        int ExecuteOperation(DataTable dataTable);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        IDictionary<string, object> ExecuteObjectQuery(object parameters);
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="parameters"></param>
        /// <returns></returns>
        T ExecuteObjectQuery<T>(object parameters) where T : class;

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        ResultSet ExecuteDataQuery();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        ResultSet ExecuteDataQuery(object parameters);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="maxRowCount"></param>
        /// <returns></returns>
        ResultSet ExecuteDataQuery(int maxRowCount);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="maxRowCount"></param>
        /// <returns></returns>
        ResultSet ExecuteDataQuery(object parameters, int maxRowCount);

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        ResultSet<T> ExecuteDataQuery<T>() where T : new();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="maxRowCount"></param>
        /// <returns></returns>
        ResultSet<T> ExecuteDataQuery<T>(int maxRowCount) where T : new();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        ResultSet<T> ExecuteDataQuery<T>(object parameters) where T : new();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="maxRowCount"></param>
        /// <returns></returns>
        ResultSet<T> ExecuteDataQuery<T>(object parameters, int maxRowCount) where T : new();

        /// <summary>
        /// 
        /// </summary>
        /// <param name="dataTable"></param>
        void FillDataTable(DataTable dataTable);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dataTable"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        void FillDataTable(DataTable dataTable, object parameters);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dataSet"></param>
        void FillDataSet(DataSet dataSet);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dataSet"></param>
        /// <param name="parameters"></param>
        void FillDataSet(DataSet dataSet, object parameters);
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        DataTable LoadDataTable();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        DataTable LoadDataTable(object parameters);
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        DataSet LoadDataSet();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        DataSet LoadDataSet(object parameters);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="sortFields"></param>
        /// <returns></returns>
        PagedResultSet ExecuteDataQuery(int pageIndex, int pageSize, IDictionary<string, bool> sortFields);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="sortFields"></param>
        /// <returns></returns>
        PagedResultSet ExecuteDataQuery(int pageIndex, int pageSize, IDictionary<string, bool> sortFields, object parameters);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="sortFields"></param>
        /// <returns></returns>
        PagedResultSet<T> ExecuteDataQuery<T>(int pageIndex, int pageSize, IDictionary<string, bool> sortFields) where T : new();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="sortFields"></param>
        /// <returns></returns>
        PagedResultSet<T> ExecuteDataQuery<T>(int pageIndex, int pageSize, IDictionary<string, bool> sortFields, object parameters) where T : new();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="sortFields"></param>
        /// <returns></returns>
        DataTable LoadDataTable(int pageIndex, int pageSize, IDictionary<string, bool> sortFields);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="sortFields"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        DataTable LoadDataTable(int pageIndex, int pageSize, IDictionary<string, bool> sortFields, object parameters);
        /// <summary>
        /// 分页填充数据集
        /// </summary>
        /// <param name="dataTable">要填充的数据集</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页行数</param>
        /// <param name="sortFields">排序字段集</param>
        /// <returns>返回总行数</returns>
        int FillDataTable(DataTable dataTable, int pageIndex, int pageSize, IDictionary<string, bool> sortFields);
        /// <summary>
        /// 分页填充数据集
        /// </summary>
        /// <param name="dataTable">要填充的数据集</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页行数</param>
        /// <param name="sortFields">排序字段集</param>
        /// <param name="parameters">条件参数</param>
        /// <returns>返回总行数</returns>
        int FillDataTable(DataTable dataTable, int pageIndex, int pageSize, IDictionary<string, bool> sortFields, object parameters);
    }
}
